package com.hxd.tabactivityfragment.ui.fragment.MineOfFragment

import com.hxd.tabactivityfragment.R
import com.hxd.tabactivityfragment.bean.IMPDataInfo.IMPSucharDataInfoBean
import com.hxd.tabactivityfragment.bean.IMPDataInfo.MiklData.MiklDataDesc
import com.hxd.tabactivityfragment.bean.IMPDataInfo.MiklData.MiklDataInfo
import com.hxd.tabactivityfragment.bean.IMPDataInfo.MiklData.MiklProductInfo
import com.hxd.tabactivityfragment.bean.IMPDataInfo.MiklData.MiklProductInfoDesc
import com.hxd.tabactivityfragment.common.MyFragment
import com.hxd.tabactivityfragment.util.*
import com.kymjs.rxvolley.RxVolley
import com.kymjs.rxvolley.client.HttpCallback
import com.kymjs.rxvolley.client.HttpParams
import com.vondear.rxtool.RxSPTool
import kotlinx.android.synthetic.main.fragment_find_milk_info.*
import kotlinx.android.synthetic.main.item_milk_info.*
import kotlinx.android.synthetic.main.item_search_info.*

/**
 *  项目名：    FoodOrigins
 *  包名：      com.hxd.tabactivityfragment.ui.fragment
 *  文件名:     MilkInfoFragment
 *  创建者:     HXD
 *  创建时间:   2019/3/24 15:43
 *  描述:       奶源数据界面
 */

class MilkInfoFragment:MyFragment() {

    override fun getLayoutId(): Int {
        return R.layout.fragment_find_milk_info
    }

    override fun getTitleBarId(): Int {
        return 0
    }

    //设置单例静态方法
    companion object {
        fun newInstance(): MilkInfoFragment {
            return MilkInfoFragment()
        }
    }

    override fun initView() {
        //配置轮播图
        sib_simple_usage_milk.setSource(BannerDataUtil.getMiklDatas())
            .setOnItemClickL { position -> myToast("position--->$position") }
            .setIsOnePageLoop(false).startScroll()
    }

    override fun initData() {
        var searchData = RxSPTool.getString(context, "IMPSucharDataInfoBean")
        var bean = GsonToBean.JsonToBean<IMPSucharDataInfoBean>(searchData)
        var mikl = bean.data.milk
        var params = HttpParams()
        params.putJsonParams(GsonToBean.QueryToJson(mikl))
        RxVolley.jsonPost(URLProviderUtils.getIMPSearchUrl(),params, object : HttpCallback() {
            override fun onSuccess(result: String?) {
                var miklProduct = GsonToBean.JsonToBean<MiklProductInfo>(result).data
                var miklInfo = GsonToBean.JsonToBean<MiklProductInfoDesc>(miklProduct.desc)
                ThreadUtil.runOnMainThread(Runnable {
                    tv_milkID.text = miklProduct.id
                    tv_weight.text = miklProduct.weight.toString()
                    tv_title.text = miklInfo.title
                    tv_milkArea.text = miklInfo.area
                    tv_license.text = miklInfo.license
                    tv_prairie.text = miklInfo.prairie
                    tv_mineral.text = miklInfo.mineral
                    tv_vitamin.text = miklInfo.vitamin
                })

                var par = HttpParams()
                par.putJsonParams(GsonToBean.QueryToJson(miklProduct.creator))
                RxVolley.jsonPost(URLProviderUtils.getIMPSearchUrl(),par, object : HttpCallback() {
                    override fun onSuccess(t: String?) {
                        var data = GsonToBean.JsonToBean<MiklDataInfo>(t).data
                        L.i("MilkInfoFragment :: $data")
                        ThreadUtil.runOnMainThread(Runnable {
                            tv_MSPID.text = data.msp_id
                            var info = GsonToBean.JsonToBean<MiklDataDesc>(data.desc)
                            tv_name.text = info.name
                            tv_time.text = info.time
                            tv_area.text = info.area
                            tv_person.text = info.representative
                            tv_type.text = info.enterprise_type
                            tv_manage_scope.text = info.manage_scope
                            tv_register.text = info.registration_authority
                        })
                    }

                    override fun onFailure(errorNo: Int, strMsg: String?) {

                    }
                })
            }

            override fun onFailure(errorNo: Int, strMsg: String?) {
                L.i("FindFragment : $strMsg")
            }
        })
    }


    
}